package com.hp.ssmp.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hp.ssmp.entity.TCart;
import com.hp.ssmp.entity.TComment;
import com.hp.ssmp.entity.TGoods;
import com.hp.ssmp.entity.dto.TCommentDto;
import com.hp.ssmp.service.CommentService;
import com.hp.ssmp.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    @GetMapping("/page")
    public R<Page<TCommentDto>> page(Integer currentPage, Integer pageSize, Long userid, Long status) {
        Page<TCommentDto> commentPage = commentService.getTCommentDtoPage(currentPage, pageSize, userid,status);
        return R.success(commentPage);
    }
    @GetMapping("/del")
    public R del(Long commentid) {
        boolean result = commentService.removeById(commentid);
        if (result) {
            return R.success();
        } else {
            return R.error();
        }
    }

    @PostMapping("/add")
    public R add(TComment comment) {
        comment.setCommenttime(new Date());
        comment.setStatus(1L);
        boolean result = commentService.save(comment);
        if (result) {
            return R.success();
        } else {
            return R.error();
        }
    }
}
